<?php
	require_once($_SERVER["DOCUMENT_ROOT"]."/global.php");
	require_once($_SERVER["DOCUMENT_ROOT"]."/modules/security_mod.php");
	require_once($_SERVER["DOCUMENT_ROOT"]."/modules/channel_mod.php");

	SecurityMod::login("?returnurl=chat_channels");

	$level = $_SESSION["account"]->getLevel();
        $chatLevel = $_SESSION["account"]->getChatLevel();
	if ($level != "Admin" && $chatLevel != 3)
		SecurityMod::logout();

	$channels = ChannelMod::getChannels();
?>
<html>
<head>
<title><?php echo(SettingsMod::PAGE_TITLE." :: Channels"); ?></title>
<link rel="stylesheet" href="main.css">
</head>
<body>
	<h2 align="center">Channel List</h2>
	<table align="center" width="600">
	<tr>
		<td align="center">
			<table background="<?php echo(SettingsMod::STATIC_IMAGES)?>/bgd.gif" class="messagestyle" align="center" width="100%">
			<tr>
				<th>&nbsp;</th>
                                <th><u>ID</u></th>
				<th><u>Name</u></th>
                                <th><u>Current users</u></th>
                                <th><u>Users</u></th>
                                <th><u>Edit</u></th>
				<th><u>Delete</u></th>
			</tr>
			<?php
				$i = 0;
				foreach ($channels as $chn):
				$i++;
			?>
			<tr bgcolor='#0b0b2f'>
				<td align='right' style='cursor:crosshair'>
					<?php echo($i)?>.
				</td>
                                <td><?php echo($chn->getId()); ?></td>
				<td><?php echo($chn->getName()); ?></td>
                                <td><?php echo($chn->getUsers()); ?></td>
                                
				<!-- User admin -->
				<form action="channel_users.php" method="get">
				<td style="text-align: center">
						<input type="hidden" name="id" value="<?php echo($chn->getId()); ?>" />
						<input type="submit" value="Users" />
				</td>
				</form>
                        
				<!-- Edit -->
				<form action="channel_edit.php" method="get">
				<td style="text-align: center">
						<input type="hidden" name="id" value="<?php echo($chn->getId()); ?>" />
						<input type="submit" value="Edit" />
				</td>
				</form>

				<!-- Delete -->
				<form action="channel_delete.php" method="get">
				<td style="text-align: center">
						<input type="hidden" name="id" value="<?php echo($chn->getId()); ?>" />
						<input type="submit" value="Delete" />
				</td>
				</form>
			</tr>
			<?php endforeach; ?>
		</td>
	</tr>
	</table>

	<br />
	<h2 align="center">Create Channel</h2>
	<form method="post" action="channel_add.php">
	<table background="<?php echo(SettingsMod::STATIC_IMAGES)?>/bgd.gif" class="messagestyle" align="center">
            <tr>
                    <th>Name:</th>
                    <td><input type="text" name="name" style="width: 100%" /></td>
            </tr>
            <tr>
                    <td colspan="2" align="center"><input type="submit" value="Create Channel" style="width: 100%" /></td>
            </tr>
	</table>
	</form>
</body>
</html>
